var listUrl = basePath + "/sys/point/report/student/itemList";
var termListUrl = basePath + "/sys/dict/termList";

var dataGrid;
var schoolId = $("#userSchoolId").val();

$(function () {
    initSchoolIdValue();
    initDatebox();
    initTermList();
});

function loadData() {
    dataGrid = $('#notice').datagrid({
        url: listUrl,
        toolbar: '#tb',
        fit: true,
        fitColumns: true,
        border: true,
        pagination: true,
        idField: 'id',
        pageSize: config.pageSize,
        autoRowHeight: 140,
        pageList: config.pageList,
        queryParams: {
            termId: $("#termId").val(),
            monthDate: $("#monthDate").datebox('getValue'),
            grade: $("#grade").val(),
            clazz: $("#clazz").combobox('getValue'),
            userName: $("#userName").val(),
            schoolId: schoolId
        },
        nowrap: true,
        striped: true,
        rownumbers: true,
        columns: [[
            {
                field: 'termName',
                title: '学期',
                width: 20,
                resizable: true,
                align: "center"
            },
            {
                field: 'gradeText',
                width: 10,
                title: '班级',
                align: "center",
                formatter: function (value, row, index) {
                    return value + "(" + row.clazz + ")";
                }
            },
            {
                field: 'targetName',
                width: 10,
                title: '被评学生',
                align: "center"
            },
            {
                field: 'judgeType',
                title: '评价类别',
                width: 20,
                align: "center"
            },
            {
                field: 'judgeContent',
                title: '评价内容',
                width: 10,
                align: "center"
            },
            {
                field: 'score',
                title: '加减分',
                width: 20,
                align: "center"
            },
            {
                field: 'judgeDepart',
                title: '评价部门',
                width: 10,
                align: "center"
            },
            {
                field: 'judgeTeacher',
                title: '评价人',
                width: 10,
                align: "center"
            },
            {
                field: 'createTime',
                title: '评价日期',
                width: 10,
                align: "center",
                formatter: function (value, row, index) {
                    return getTime(value, 'yyyy-MM-dd hh:mm:ss');
                }
            }
        ]]
    });
}

function initTermList() {
    $.ajax({
        url: termListUrl,
        type: 'POST',
        dataType: 'json',
        data: {schoolId: schoolId},
        error: function (data) {
            $.messager.progress('close');
            $.messager.alert('系统提示', data.msg, 'error');
        },
        success: function (data) {
            var html = "";
            for (var i in data) {
                html += "<option value='" + data[i].id + "'>" + data[i].termName + "</option>";
            }
            $("#termId").html(html);
            loadData();
            initGradeList();
        }
    });

}

function initGradeList() {
    $.ajax({
        url: basePath + "/gradeList",
        type: "post",
        dataType: "json",
        async: false,
        success: function (data) {
            var html = '<option value="">请选择</option>';
            for (var i in data) {
                if (data.hasOwnProperty(i)) {
                    html += "<option value='" + i + "'>" + data[i] + "</option>";
                }
                ;
            }
            $("#grade").html(html);
        }, error: function () {
            alert("删除照片异常");
        }
    });
}

function initDatebox() {
    var currTime = new Date();
    var strDate = currTime.getFullYear() + '-' + (currTime.getMonth() + 1) + "-01";
    $('#monthDate').datebox({
        formatter: function (date) {
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            m = m < 10 ? '0' + m : m;
            return y.toString() + '-' + m.toString();
        }, parser: function (date) {
            if (date) {
                return new Date(String(date).substring(0, 4) + '-'
                    + String(date).substring(5, 7));
            } else {
                return new Date();
            }
        }
    });
    $('#monthDate').datebox('setValue', strDate);//默认加载当前月份
}

function reload() {
    dataGrid.datagrid("clearSelections");
    searchForm("searchForm");
}

function searchForm(formId) {
    loadData();
}

function resetForm(formId) {
    $("#" + formId)[0].reset();
    var currTime = new Date();
    var strDate = currTime.getFullYear() + '-' + (currTime.getMonth() + 1);
    $("#monthDate").datebox('setValue', strDate);
    getClazz("");
}

function exportToExcel(searchForm, exportUrl) {
    $("#" + searchForm).attr('action', exportUrl);
    $("#" + searchForm).submit();
}

